View.vue
<template>
  <h1>员工列表综合练习</h1>
  <el-form size="large" style="width:400px;margin:0 auto">
    <el-form-item label="姓名"><el-input v-model="emp.name" placeholder="请输入员工姓名"></el-input></el-form-item>
    <el-form-item label="工资"><el-input v-model="emp.salary" placeholder="请输入员工工资(请输入数字)"></el-input></el-form-item>
    <el-form-item label="岗位"><el-input v-model="emp.job" placeholder="请输入员工岗位"></el-input></el-form-item>
    <el-form-item><el-button type="success" @click="add">提交</el-button></el-form-item>
  </el-form>
  <br><br>
  <el-table :data="emps" style="width:50%;margin:0 auto">
    <el-table-column label="编号" type="index" width="100px" align="center"></el-table-column>
    <el-table-column label="姓名" prop="name" align="center"></el-table-column>
    <el-table-column label="工资" prop="salary" align="center"></el-table-column>
    <el-table-column label="岗位" prop="job" align="center"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
    </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
  import {ref} from "vue";

  const emp = ref({name:'',salary:'',job:''});
  const emps = ref([]);
  const add = () => {
    if(!emp.value.name || !emp.value.name.trim()
       || !emp.value.salary || !emp.value.salary.trim()
       || !emp.value.job || !emp.value.job.trim()
    ){
      return alert("请输入正确的信息");
    }
    if(!/^\d+$/.test(emp.value.salary)){
      return alert("工资栏只能输入数字且不能包含空格");
    }
    emp.value.name=emp.value.name.trim();
    emp.value.job=emp.value.job.trim();
    emps.value.push(emp.value);
    emp.value = {};
  }
  const del = (index,emp) =>{
    if(confirm("确认删除"+emp.name+"吗？")){
      emps.value.splice(index,1);
    }
  }
</script>

<style scoped>

</style>